<?php

/**
 * Description of login
 *
 * @author Agustin Suaña
 */
class Login extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('login_model');
    }

        function index() {
        $this->load->view('login_vista');
    }

    function verificar() {
        $this->form_validation->set_rules('usuario', 'usuario', 'required|trim');
        $this->form_validation->set_rules('password', 'password', 'required|trim');
        $this->form_validation->set_message('required', 'el campo %s es obligatorio');
        $this->form_validation->set_error_delimiters('<span class="error">', '</span>');
        if ($this->form_validation->run() == FALSE) {
            $this->load->view('login_vista');
        } else {
            $usuario = $this->input->post('usuario');
            $password = $this->input->post('password');
            $exito = $this->login_model->verificar_usuario($usuario, $password);
            if($exito){
                redirect('admin/inicio');
            }else{
                $data['error'] = 'El usuario y/o password son incorrectos <br />o no existen';
                $this->load->view('login_error_vista', $data);
            }
        }
    }
    
    function logout(){
        redirect('login');
    }

}

/* End of file login.php */
/* Location: ./application/controllers/login.php */